import path from 'path'
import Koa from 'koa'
import views from 'koa-views'
import { createView } from './view/mark-view'
import dayjs from 'dayjs'
import { MarkApi } from './controller'
const config = require('../etc/config')


export async function serve(config:any) {
    const app = new Koa()
    const { host } = config
    const {tpl,port} = config
    const binance = new MarkApi(host, '/api/v3')
    const req:any = {symbol:"ETHBTC"}
    binance.klinesYear(req)
    const cwd = process.cwd()
    console.log(dayjs().year().valueOf())
    app.use(views(path.join(cwd, tpl), {
        extension: 'ejs'
    }))

    const view = await createView(config)
    app.use(view)

    app.listen(port,()=>{
        console.log(`监听端口${port}`)
    })
}

